package com.inepex.inechart.shared.linechart;

import java.util.ArrayList;
import java.util.Comparator;

import com.inepex.inechart.shared.data.KeyValueDataEntry;
@SuppressWarnings("rawtypes")
public class Point implements Comparable<Point>{
	public static Comparator<Point> canvasXComparator = new Comparator<Point>() {

		@Override
		public int compare(Point o1, Point o2) {
			return Double.compare(o1.canvasX, o2.canvasX);
		}
	};
	protected KeyValueDataEntry entry;
	protected ArrayList<Point> filteredPoints;
	protected double[] valuePairForFiltered;
	protected Point bestMatchingFilteredPoint;
	protected double canvasX, canvasY;
	protected boolean isInViewport;
	protected boolean unfilterable = false;

	public Point(double x, double y) {
		filteredPoints = new ArrayList<Point>();
		this.valuePairForFiltered = new double[]{x,y};
	}

	public Point(KeyValueDataEntry entry) {
		this.entry = entry;
	}

	protected void addFilteredPoint(Point dp){
		filteredPoints.add(dp);
	}

	public boolean containsHiddenData(){
		return filteredPoints == null;
	}

	public ArrayList<Point> getFilteredPoints(){
		return filteredPoints;
	}


	public boolean isInViewport() {
		return isInViewport;
	}

	public double getCanvasX() {
		return canvasX;
	}

	public double getCanvasY() {
		return canvasY;
	}

	public Point getBestMatchingFilteredPointOrThis() {
		return bestMatchingFilteredPoint == null ? this : bestMatchingFilteredPoint;
	}

	@Override
	public int compareTo(Point o) {
		int compare = Double.compare(canvasX, o.canvasX);
		if(compare == 0){
			compare = Double.compare(canvasY, o.canvasY);
		}
		return compare;
	}

	public KeyValueDataEntry getEntry() {
		return entry;
	}


	public double[] getUnderLyingData(){
		return valuePairForFiltered == null ? entry.getValuePair() : valuePairForFiltered;
	}

}
